gh-130824: Add tests for NULL in PyLong_*AndOverflow functions#130828
Conversation
skirpichev
left a comment
There was a problem hiding this comment.
LGTM
Few nitpicks, feel free to ignore.
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
| self.assertEqual(func(max_val + 1), (-1, +1)) | ||
| self.assertRaises(SystemError, func, None) | ||
|
|
||
| # CRASHES func(1.0) |
There was a problem hiding this comment.
Good catch, it doesn't: "If any other exception occurs set *overflow to 0 and return -1 as usual." TypeError will be here.
| if (value == -1 && PyErr_Occurred()) { | ||
| assert(overflow == -1); | ||
| // overflow can be 0 if a seperate exception occurred | ||
| assert(overflow == -1 || overflow == 0); |
There was a problem hiding this comment.
Yeah, OverflowError is -1 and then other exceptions (only SystemError?) are 0.
There was a problem hiding this comment.
only SystemError?
No, TypeError too.
There was a problem hiding this comment.
OverflowError is not raised. In case of an integer overflow, *overflow should be 1 or -1.
Isn't it always 0 here?
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
|
Thanks @ZeroIntensity for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
|
Thanks @ZeroIntensity for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Sorry, @ZeroIntensity and @encukou, I could not cleanly backport this to |
…ons (pythonGH-130828) (cherry picked from commit 9013080) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
|
GH-130869 is a backport of this pull request to the 3.13 branch. |
|
@encukou Should I make the manual backport to 3.12? I'm not sure it's worth backporting to prevent conflicts if there's already a conflict. |
|
It will help to backport future tests. It will help to ensure that no regressions be introduced in old versions. See also #130871. You can include that change in the backports. |
… functions (pythonGH-130828) (cherry picked from commit 9013080) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
|
GH-130876 is a backport of this pull request to the 3.12 branch. |
Sorry, I did it before I saw your message |
… functions (pythonGH-130828) (cherry picked from commit 9013080) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
…GH-130828) (GH-130876) (cherry picked from commit 9013080) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
It crashed before because the assertion didn't realize that
overflowwould be 0 and not -1 inSystemErrorcases.